package com.jacobson.core.utils

import android.annotation.SuppressLint
import android.content.Context

/**
 * ================================================
 *
 *  @author Wucz on 2018/7/25 10:47
 * ================================================
 */

class DeviceUtil constructor(val context: Context) {
    companion object {
        @SuppressLint("StaticFieldLeak")
        private lateinit var INSTANCE: DeviceUtil

        internal fun init(context: Context) {
            INSTANCE = DeviceUtil(context)
        }

        fun dp2px(dp: Float): Int {
            val scale = INSTANCE.context.resources.displayMetrics.density
            return (dp * scale + 0.5f).toInt()
        }

        fun sp2px(sp: Float): Int {
            val scale = INSTANCE.context.resources.displayMetrics.scaledDensity
            return (sp * scale + 0.5f).toInt()
        }
    }
}